
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Drag Delegation with a Drop Target</title>

<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
	margin:0;
	padding:0;
}
</style>

<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" />
<script type="text/javascript" src="../../build/yui/yui-min.js"></script>

<!--there is no custom header content for this example-->

</head>

<body class="yui3-skin-sam  yui-skin-sam">

<h1>Drag Delegation with a Drop Target</h1>

<div class="exampleIntro">
	<p>This example shows how to create multiple draggable items efficiently, still allowing for Drop Targets.</p>
			
</div>

<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->

<style>
    #demo {
        width: 200px;
    }
    #demo ul li {
        border: 1px solid black;
        background-color: #8DD5E7;
        cursor: move;
        margin: 3px;
        list-style-type: none;
        z-index: 2;
    }
    #play {
        position: relative;
    }
    #drop {
        border: 1px solid black;
        background-color: #eee;
        height: 50px;
        width: 200px;
        position: absolute;
        bottom: 5px;
        right: 5px;
    }
    #drop strong {
        font-weight: bold;
    }
    #drop.yui3-dd-drop-over {
        background-color: #ccc;
    }
</style>

<div id="play">

    <div id="demo">
        <ul>
            <li>Item #1</li>
            <li>Item #2</li>
            <li>Item #3</li>
            <li>Item #4</li>
            <li>Item #5</li>
            <li>Item #6</li>
            <li>Item #7</li>
            <li>Item #8</li>
            <li>Item #9</li>
            <li>Item #10</li>
        </ul>
    </div>
    
    <div id="drop">Drop on me</div>
</div>

<script>

YUI().use('dd-delegate', 'dd-drop-plugin', function(Y) {
    var del = new Y.DD.Delegate({
        container: '#demo',
        nodes: 'li'
    });

    del.on('drag:end', function(e) {
        del.get('currentNode').setStyles({
            top: 0,
            left: 0
        });
    });

    var drop = Y.one('#drop').plug(Y.Plugin.Drop);
    drop.drop.on('drop:hit', function(e) {
        drop.set('innerHTML', 'You dropped: <strong>' + e.drag.get('node').get('innerHTML') + '</strong>');
    });
    

});
</script>

<!--END SOURCE CODE FOR EXAMPLE =============================== -->

</body>
</html>
